package com.huixh.train.batch.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.huixh.train.batch.client.BusinessClient;
import com.huixh.train.common.resp.Result;
import jakarta.annotation.Resource;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.Date;

/**
 * @author huixh
 */
@DisallowConcurrentExecution
public class DailyTrainJob implements Job {
    private final Logger logger = LoggerFactory.getLogger(DailyTrainJob.class);
    @Resource
    private BusinessClient businessClient;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        MDC.put("LOG_ID", System.currentTimeMillis() + RandomUtil.randomString(3));
        logger.info("生成15天后车次执行开始");
        Date date = new Date();
        DateTime offsetDay = DateUtil.offsetDay(date, 15);
        Date offsetDayJdkDate = offsetDay.toJdkDate();
        Result<String> result = businessClient.genDaily(offsetDayJdkDate);
        logger.info("每日生成车次执行完毕,执行结果:{}",result);
        MDC.clear();
    }
}
